//
//  ViewController.swift
//  SwiftDemo
//
//  Created by cqf on 2025/8/21.
//

import UIKit
import Alamofire

protocol HttpProtocol {
   // var delegate:HttpProtocol?
    func didRecieveResults(result:AnyObject)
}



class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //网络请求
        AF.request("https://httpbin.org/get").response { response in
            debugPrint(response)
        }
        AF.request("https://api.example.com/data").responseJSON { response in
            // 处理服务器响应
            if case .success(let value) = response.result {
                print("成功获取到数据：(value)")
            } else if case .failure(let error) = response.result {
                print("请求失败，错误信息：(error)")
            }
        }
        // Automatic String to URL conversion, Swift concurrency support, and automatic retry.
        
        
        //
        let label = UILabel(frame: CGRectMake(20, 20, 100, 30))
        label.backgroundColor = .gray
        label.text = "hello world"
        label.font = UIFont.systemFont(ofSize: 12)
        label.textColor = .red
        label.textAlignment = .center
        self.view.addSubview(label)
        
        //
        let button = UIButton(type: .custom)
        button.frame = CGRectMake(100, 200, 100, 100)
        button.backgroundColor = .yellow
        button.addTarget(self, action: #selector(changeColor(_:)), for: .touchUpInside)
        self.view.addSubview(button)
        // 使用自动布局设置按钮位置（居中显示）
        
        //测试break
        for i in 0..<3 {
            print(i);
            if i == 1 {
                break
            }
        }
        let names = ["Anna", "Alex", "Brian", "Jack"]
        for name in names {
            print("Hello, \(name)!")
        }
    }
    
    // 按钮点击事件处理方法
    @objc func changeColor(_ sender: UIButton) {
        let proListVC = ProductListViewController()
        
        let cardVC = CardScrollVC()
        cardVC.modalPresentationStyle = .fullScreen
        present(cardVC, animated: true)
        
        // 改变按钮标题
        sender.setTitle("已点击", for: .normal)
        
        // 改变按钮背景色
        sender.backgroundColor = .systemGreen
        
        // 显示提示框
        let alert = UIAlertController(title: "提示", message: "按钮被点击了！", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "确定", style: .default))
        present(alert, animated: true)
    }
    
    override func viewWillAppear(_ animated: Bool) {
//        let alert = UIAlertController(title: "提示", message: "按钮被点击了！", preferredStyle: .alert)
//        alert.addAction(UIAlertAction(title: "确定", style: .default))
//        present(alert, animated: true)
        
        var modelAry:[String] = ["test","apple","banana"]
        for item in modelAry {
            print(item)
        }
        
        for (index,value) in modelAry.enumerated() {
            print(String(index),value)
        }
        //bundle路径
       // let psth = Bundle.main.path(forResource: "test", ofType: "json")!
        //元组
        let testyuanzu = (name:"test",age:13,height:199)
    }
    
}


class testView: UIView {
    override func draw(_ rect: CGRect) {
        let p = UIBezierPath(ovalIn: bounds)
        UIColor.red.setFill()
        p.fill()
    }
}

class Person {
    var name: String = ""
}

class Student: Person {
    override var name: String {
        didSet {
            print("\(name)")
        }
    }
}

